/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gruppe1projekt.ControllerLayer;

import gruppe1projekt.ModelLayer.*;
import java.util.Date;
import java.util.ArrayList;
import java.util.GregorianCalendar;

/**
 *
 * @author Kristian Byrialsen
 */
public class ProductController
    {

    public ProductController()
    {


    }

    public void createProduct(String Name, String Description, int PurchasePrice, long Barcode, int Count)
    {
        Product P = new Product();
        P.setName(Name);
        P.setDescription(Description);
        P.setPurchasePrice(PurchasePrice);
        P.setBarcode(Barcode);
        P.setCount(Count);
        P.setIsUnique(false);


        //tilføjer det nye produkt til vores produktcontainer
        ProductContainer.getInstance().createProduct(P);
    }
    // Finder product fra container og returnere tilbage til TUI

    public Product getProduct(long Barcode)
    {
        return ProductContainer.getInstance().getProduct(Barcode);
    }

    public void updateProduct(String Name, String Description, int SalePrice, int PurchasePrice, int DiscountPrice, long Barcode, int Count)
    {
        Product P = new Product();
        P.setName(Name);
        P.setDescription(Description);
        P.setPurchasePrice(PurchasePrice);
        P.setBarcode(Barcode);
        P.setCount(Count);
        P.setIsUnique(false);

        //Updater produktet via barcode
        ProductContainer.getInstance().updateProduct(P);
    }

    public void deleteProduct(long Barcode)
    {
        ProductContainer PC = ProductContainer.getInstance();
        PC.deleteProduct(PC.getProduct(Barcode));
    }
//add number

    public void addCount(long Barcode, int Number)
    {
        ProductContainer PC = ProductContainer.getInstance();
        Product P = PC.getProduct(Barcode);
        PC.addCount(P, Number);
    }

    //Her blir der tilføjet et givent serialnummer til et produkt.
    public void addProductItem(long Barcode, int SerialNumber)
    {
        ProductItem PI = new ProductItem(SerialNumber);
        ProductContainer.getInstance().addProductItem(Barcode, PI);
    }

    // Her blir der tilføjet en given pris til en bestemt dato.
    public void addPrice(long Barcode, Date StartDate, Date EndDate, Employee employee, int price, boolean IsDiscount)
    {
        Price P = new Price(StartDate, EndDate, employee, price, IsDiscount);
        ProductContainer.getInstance().addPrice(Barcode, P);
    }
    //Får listen af productitems fra det valgte produkt.

    public ArrayList<ProductItem> getProductItems(long Barcode)
    {
        return ProductContainer.getInstance().getProductItems(Barcode);
    }

    public Price CurrentPrice(long Barcode)
    {
        ArrayList<Price> PL = ProductContainer.getInstance().getPrice(Barcode);
        for (Price P : PL)
        {
            if (P.IsDiscount())
            {
                return P;
            }
        }
        return null;
    }

    public ArrayList<Product> getProducts()
    {
        return ProductContainer.getInstance().getProductList();
    }
    }

